import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-08-16
 * Time: 15:03
 * To BE A Better Person-2020-3-2
 */

class MyThreadPool{
    private BlockingQueue<Runnable> queue=new LinkedBlockingQueue<>();

    public void submit(Runnable run) throws InterruptedException {
        queue.put(run);
    }

    public MyThreadPool(int n){
        for (int i = 0; i < n; i++) {
            Thread t=new Thread(()->{
                try {
                    Runnable runnable=queue.take();
                    runnable.run();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
            t.start();
        }
    }
}
public class TestDemo {
    public static void main(String[] args) throws InterruptedException {
        MyThreadPool pool=new MyThreadPool(10);
        pool.submit(()->{
            while(true){
                System.out.println("hello");
            }
        });
    }
}
